package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/18 11:09
 * @description
 */
public class Code844 {
    public boolean backspaceCompare(String S, String T) {
        String s1 = getString(S);
        String s2 = getString(T);
        return s1.equals(s2);
    }

    private String getString(String s) {
        int i = s.indexOf("#");
        if (i == 0) {
            return getString(s.substring(1));
        }
        if (i > 0) {
            return getString(s.substring(0, i - 1) + s.substring(i + 1));
        }
        return s;
    }
}
